#coding=utf-8
'''
2.7. Specifying a Regular Expression for the Shortest Match
 add the  ? modifier after the  * operator in the pattern,
 produces the shortest match

In a pattern, the dot matches any
character except a newline. However, if you bracket the dot with starting and ending
text (such as a quote), matching will try to find the longest possible match to the pattern.
This causes multiple occurrences of the starting or ending text to be skipped altogether
and included in the results of the longer match. Adding the  ? right after operators such
as  * or  + forces the matching algorithm to look for the shortest possible match instead
'''
import re
str_pat = re.compile(r'\"(.*)\"')
text1 = 'Computer says "no."'
a = str_pat.findall(text1)
print(a)
text2 = 'Computer says "no." Phone says "yes."'
b = str_pat.findall(text2)
print(b)

# ?
str_pat2 = re.compile(r'\"(.*?)\"')
c = str_pat2.findall(text2)
print(c)
